library(foreign)

A <- read.dta("study 1 wave 2.dta")


#speech versus safety
A$safety[A$speech==1] <- 0

#believe rally should be allowed
A$allow <- ifelse(A$kkk_banrally==0, 1, 0)


#full model
mod1 <- lm(allow ~ safety, data=A[A$trained==0,])

#0 screeners correct
mod2 <- lm(allow ~ safety, data=A[A$trained==0 & A$screen==0,])

mod2_beta <- coef(mod2)
mod2_conf <- confint(mod2)

#1 screener correct
mod3 <- lm(allow ~ safety, data=A[A$trained==0 & A$screen==0.25,])

mod3_beta <- coef(mod3)
mod3_conf <- confint(mod3)

#2 screeners correct
mod4 <- lm(allow ~ safety, data=A[A$trained==0 & A$screen==0.5,])

mod4_beta <- coef(mod4)
mod4_conf <- confint(mod4)

#3 screener correct
mod5 <- lm(allow ~ safety, data=A[A$trained==0 & A$screen==0.75,])

mod5_beta <- coef(mod5)
mod5_conf <- confint(mod5)

#4 screeners correct
mod6 <- lm(allow ~ safety, data=A[A$trained==0 & A$screen==1,])

mod6_beta <- coef(mod6)
mod6_conf <- confint(mod6)


betas <- cbind(mod2_beta[2], mod3_beta[2], mod4_beta[2], mod5_beta[2], mod6_beta[2])

lb <- cbind(mod2_conf[2,1], mod3_conf[2,1], mod4_conf[2,1], mod5_conf[2,1], mod6_conf[2,1])

ub <- cbind(mod2_conf[2,2], mod3_conf[2,2], mod4_conf[2,2], mod5_conf[2,2], mod6_conf[2,2])

time <- rep(0:4)

png("figure5.png", width=5,height=5,units="in",res=1200)

y.at=c(-0.8, -0.6, -0.4, -0.2, 0, 0.2)
x.at=c(0,1,2,3,4)
plot(time, betas, axes=F, type="n", ylab="Effect on belief that rally should be allowed", xlab="Number of Screeners Answered Correctly", ylim=c(-0.8, 0.2), xlim=c(0,4))
segments(time[1], lb[1], time[1], ub[1], lty=1, col="grey")
segments(time[2], lb[2], time[2], ub[2], lty=1, col="grey")
segments(time[3], lb[3], time[3], ub[3], lty=1, col="grey")
segments(time[4], lb[4], time[4], ub[4], lty=1, col="grey")
segments(time[5], lb[5], time[5], ub[5], lty=1, col="grey")
lines(time, betas, lty=2)
points(time, betas, pch=16)
axis(1, x.at)
axis(2, y.at)
abline(h=0,lty=3)

dev.off()

